/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.meter.service.impl;

import org.springblade.modules.meter.entity.MeterUsage;
import org.springblade.modules.meter.vo.MeterUsageVO;
import org.springblade.modules.meter.mapper.MeterUsageMapper;
import org.springblade.modules.meter.service.IMeterUsageService;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.modules.system.vo.MeterDailyUsage;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.math.BigDecimal;
import java.util.List;

/**
 * 电表记录表 服务实现类
 *
 * @author John
 * @since 2020-08-01
 */
@Service
public class MeterUsageServiceImpl extends BaseServiceImpl<MeterUsageMapper, MeterUsage> implements IMeterUsageService {

	@Override
	public IPage<MeterUsageVO> selectMeterUsagePage(IPage<MeterUsageVO> page, MeterUsageVO meterUsage) {
		return page.setRecords(baseMapper.selectMeterUsagePage(page, meterUsage));
	}

	public List<MeterDailyUsage> getMeterDailyUsage(String ammeterNo, String enprNo, int readType) {
		switch (readType) {
			case 0: return baseMapper.getAmmeterTotalDailyUsage(ammeterNo, enprNo);
			case 1: return baseMapper.getAmmeterSharpDailyUsage(ammeterNo, enprNo);
			case 2: return baseMapper.getAmmeterPeekDailyUsage(ammeterNo, enprNo);
			case 3: return baseMapper.getAmmeterFlatDailyUsage(ammeterNo, enprNo);
			case 4: return baseMapper.getAmmeterLowDailyUsage(ammeterNo, enprNo);
			default: return null;
		}
	}

	/**
	 * 小区使用总量
	 * @param cid
	 * @param startLine
	 * @param endLine
	 * @param enprNo
	 * @return
	 */
	public BigDecimal getCommunityUsage(int cid, long startLine, long endLine, String enprNo) {
		BigDecimal now = baseMapper.getCommunityUsage(cid, startLine, endLine, enprNo);
		now = now == null ? BigDecimal.ZERO : now;
		return now;
	}
}
